def shape(A):
    num_rows = len(A)
    num_cols = len(A[0]) if A else 0  # 第一行中元素的个数
    return num_rows, num_cols


def get_row(A, i):
    return A[i]  # A[i]是第i行


def get_column(A, j):
    return [A_i[j]  # 第A_i行的第j个元素
            for A_i in A]  # 对每个A_i行


def make_matrix(num_rows, num_cols, entry_fn):
    """returns a num_rows x num_cols matrix
    whose (i,j)th entry is entry_fn(i, j)"""
    return [[entry_fn(i, j)  # 根据i创建一个列表
             for j in range(num_cols)]  # [entry_fn(i, 0), ... ]
            for i in range(num_rows)]  # 为每一个i创建一个列表


def is_diagonal(i, j):
    """1's on the 'diagonal', 0's everywhere else"""
    return 1 if i == j else 0


identity_matrix = make_matrix(5, 5, is_diagonal)


